<?php
class log
{
    private static $log = array();
    public static function debug($title, $text = '' , $mysql = false)
    {
        if(is_array($title) || is_object($title))
        {
            $title = print_r($title,1);
        }
        if(is_array($text) || is_object($text))
        {
            $text = print_r($text,1);
        }
        self::$log[] = array(time(),$title,$text,$mysql);
    }

    public static function save($user_id,$request,$execution_time,$response)
    {
        if(count(self::$log))
        {
            $log = json_encode(self::$log);
            $logtime = time();

            $request = '\''.mysql_escape_string($request).'\'';
            $response = '\''.mysql_escape_string($response).'\'';
            $log = '\''.mysql_escape_string($log).'\'';
            
            $query = 'INSERT INTO `log` SET
`user_id`='.$user_id.',
`request`='.$request.',
`execution_time`='.$execution_time.',
`log`='.$log.',
`logtime`='.$logtime.',
`response`='.$response;
            _database::query($query);
        }
    }
}
?>
